/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Trp_datosDAOImpl implements orm.dao.Trp_datosDAO {
	public Trp_datos loadTrp_datosByORMID(int da_id_datos) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_datosByORMID(session, da_id_datos);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos getTrp_datosByORMID(int da_id_datos) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_datosByORMID(session, da_id_datos);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByORMID(int da_id_datos, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_datosByORMID(session, da_id_datos, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos getTrp_datosByORMID(int da_id_datos, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_datosByORMID(session, da_id_datos, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByORMID(PersistentSession session, int da_id_datos) throws PersistentException {
		try {
			return (Trp_datos) session.load(orm.Trp_datos.class, new Integer(da_id_datos));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos getTrp_datosByORMID(PersistentSession session, int da_id_datos) throws PersistentException {
		try {
			return (Trp_datos) session.get(orm.Trp_datos.class, new Integer(da_id_datos));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByORMID(PersistentSession session, int da_id_datos, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_datos) session.load(orm.Trp_datos.class, new Integer(da_id_datos), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos getTrp_datosByORMID(PersistentSession session, int da_id_datos, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_datos) session.get(orm.Trp_datos.class, new Integer(da_id_datos), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos[] listTrp_datosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_datosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos[] listTrp_datosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_datosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos[] listTrp_datosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_datos as Trp_datos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Trp_datos[]) list.toArray(new Trp_datos[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos[] listTrp_datosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_datos as Trp_datos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Trp_datos[]) list.toArray(new Trp_datos[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_datosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_datosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Trp_datos[] trp_datoses = listTrp_datosByQuery(session, condition, orderBy);
		if (trp_datoses != null && trp_datoses.length > 0)
			return trp_datoses[0];
		else
			return null;
	}
	
	public Trp_datos loadTrp_datosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Trp_datos[] trp_datoses = listTrp_datosByQuery(session, condition, orderBy, lockMode);
		if (trp_datoses != null && trp_datoses.length > 0)
			return trp_datoses[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTrp_datosByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_datosByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_datosByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_datosByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_datosByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_datos as Trp_datos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_datosByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_datos as Trp_datos");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos createTrp_datos() {
		return new orm.Trp_datos();
	}
	
	public boolean save(orm.Trp_datos trp_datos) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().saveObject(trp_datos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Trp_datos trp_datos) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().deleteObject(trp_datos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_datos trp_datos)throws PersistentException {
		try {
			if(trp_datos.getAlumno_id_rut() != null) {
				trp_datos.getAlumno_id_rut().trp_datos.remove(trp_datos);
			}
			
			return delete(trp_datos);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_datos trp_datos, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(trp_datos.getAlumno_id_rut() != null) {
				trp_datos.getAlumno_id_rut().trp_datos.remove(trp_datos);
			}
			
			try {
				session.delete(trp_datos);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Trp_datos trp_datos) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().refresh(trp_datos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Trp_datos trp_datos) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().evict(trp_datos);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_datos loadTrp_datosByCriteria(Trp_datosCriteria trp_datosCriteria) {
		Trp_datos[] trp_datoses = listTrp_datosByCriteria(trp_datosCriteria);
		if(trp_datoses == null || trp_datoses.length == 0) {
			return null;
		}
		return trp_datoses[0];
	}
	
	public Trp_datos[] listTrp_datosByCriteria(Trp_datosCriteria trp_datosCriteria) {
		return trp_datosCriteria.listTrp_datos();
	}
}
